<?php

header('Content-type:text/html;charset=utf-8');
require_once 'XunSearch.php';
require_once 'Model.php';

$configPath = dirname(__FILE__) . '/sdk/php/app/';


$model = new Model('xs_test');

if (isset($_POST) && !empty($_POST)) {
    $data = $_POST;
    $data['create_time'] = time();

    $insertId = $model->add($data);

    if ($insertId) {
        $data = $_POST;
        $data['id'] = $insertId;

        try {
            $xunSearch = new XunSearch($configPath. 'demo.ini');
            $xunSearch->addIndex($data);

        } catch (XSException $e) {
            echo $e;
        }
        echo '添加成功';
        sleep(2);
        header('Location:add.php');

    } else {
        echo '添加失败';exit();
    }

}






?>


<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>添加文章</title>
    <style>
        *{padding: 0;margin: 0;}
        form{ width: 600px; margin: 0 auto; }
        .form-group{padding: 10px;margin: 10px; }
        .form-group input{width: 400px;height: 25px;margin-top: 10px;}
        .form-group textarea{width: 400px;height: 400px;margin-top: 10px;}
        .form-group button{margin: 10px; width: 50px;}
    </style>
</head>
<body>
<form action="add.php" method="post">
    <div class="form-group">
        <h5>文章标题：</h5><input type="text" name="title">
    </div>
    <div class="form-group">
        <h5>文章内容：</h5>
        <textarea name="content"></textarea>
    </div>
    <div class="form-group">
        <button type="submit">提交</button>
    </div>
</form>
</body>
</html>
